package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    //分页查询
    Page<Setmeal> pageQuery(String queryString);


    //根据id查询套餐
    @Select("select * from t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    //编辑套餐
    @Update("update t_setmeal set code = #{code},name = #{name},helpCode = #{helpCode}," +
            "sex = #{sex},age = #{age},price = #{price},remark = #{remark},attention = #{attention},img = #{img}" +
            " where id = #{id}")
    void edit(Setmeal setmeal);

    //编辑套餐
    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{id}")
    void deleteCheckGroupAndSetmeal(Integer id);
    //编辑套餐
    @Insert("insert into t_setmeal_checkgroup values(#{setmealId},#{checkGroupId})")
    void setSetmealAndCheckGroup(Integer setmealId,Integer checkGroupId);


    /**
     * 添加套餐
     * @param setmeal
     */
    void add(Setmeal setmeal);


    /**
     * 查询所有图片
     * @return
     */
    @Select("select img from t_setmeal")
    List<String> getImgList();


    @Select("select name from t_setmeal")
    List<String> getSetmealNames();


    @Select("SELECT `s`.`name` ,COUNT(o.`id`) AS `value` " +
        "FROM t_setmeal s LEFT JOIN `t_order` o ON s.`id` = o.`setmeal_id` GROUP BY s.`name`")
    List<Map<String, Object>> values();

}
